/*
* Copyright (c) 2007 by Kirill Kolodyazhniy.
* See the file "license.terms" for information on usage and redistribution.
*/

#include "color.h"

namespace Engine
{
	/*******************************************************************************/
    Color Color::Black = Color(0.0,0.0,0.0);
    Color Color::White = Color(1.0,1.0,1.0);
    Color Color::Red = Color(1.0,0.0,0.0);
    Color Color::Green = Color(0.0,1.0,0.0);
    Color Color::Blue = Color(0.0,0.0,1.0);
	/*******************************************************************************/
    RGBA Color::GetAsRGBA(void) const
    {
        unsigned char val8;
        unsigned int val32 = 0;

        // Red
        val8 = static_cast<unsigned char>(r * 255);
        val32 = val8 << 24;

        // Green
        val8 = static_cast<unsigned char>(g * 255);
        val32 += val8 << 16;

        // Blue
        val8 = static_cast<unsigned char>(b * 255);
        val32 += val8 << 8;

        // Alpha
        val8 = static_cast<unsigned char>(a * 255);
        val32 += val8;

        return val32;
    }
   	/*******************************************************************************/
    ARGB Color::GetAsARGB(void) const
    {
        unsigned char val8;
        unsigned int val32 = 0;

        // Convert to 32bit pattern
        // (ARGB = 8888)

        // Alpha
        val8 = static_cast<unsigned char>(a * 255);
        val32 = val8 << 24;

        // Red
        val8 = static_cast<unsigned char>(r * 255);
        val32 += val8 << 16;

        // Green
        val8 = static_cast<unsigned char>(g * 255);
        val32 += val8 << 8;

        // Blue
        val8 = static_cast<unsigned char>(b * 255);
        val32 += val8;


        return val32;
    }
   	/*******************************************************************************/
    ABGR Color::GetAsABGR(void) const
    {
        unsigned char val8;
        unsigned int val32 = 0;

        // Alpha
        val8 = static_cast<unsigned char>(a * 255);
        val32 = val8 << 24;

        // Blue
        val8 = static_cast<unsigned char>(b * 255);
        val32 += val8 << 16;

        // Green
        val8 = static_cast<unsigned char>(g * 255);
        val32 += val8 << 8;

        // Red
        val8 = static_cast<unsigned char>(r * 255);
        val32 += val8;


        return val32;
    }
    /*******************************************************************************/
    bool Color::operator==(const Color& rhs) const
    {
		return (r == rhs.r &&
            g == rhs.g &&
            b == rhs.b &&
            a == rhs.a);
    }
    /*******************************************************************************/
    bool Color::operator!=(const Color& rhs) const
    {
        return !(*this == rhs);
    }
	/*******************************************************************************/
}
